<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">    
    <xsl:template match="info">
        <xsl:apply-templates select="category" />
    </xsl:template>
    <xsl:template match="category">
        <xsl:element name="menu">
            <xsl:attribute name="label">
                <xsl:value-of select="@name" />
            </xsl:attribute> 
            <xsl:attribute name="tooltiptext">
                <xsl:value-of select="@name" />
            </xsl:attribute>
            <menupopup>
                <xsl:for-each select="forum">
                    <xsl:choose>
                        <xsl:when test="not(count(forum))">
                            <xsl:apply-templates select="." mode="single" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="." mode="expand" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
            </menupopup>
        </xsl:element>
    </xsl:template>
    <xsl:template match="forum" mode="single">
        <xsl:element name="menuitem">
            <xsl:attribute name="label">
                <xsl:value-of select="@name" />
            </xsl:attribute>  
            <xsl:attribute name="tooltiptext">
                <xsl:value-of select="@name" />
            </xsl:attribute>
            <xsl:attribute name="id">
                <xsl:value-of select="concat('vingradmenu-tb-forumlist-forum-',@id)" />
            </xsl:attribute>
            <xsl:attribute name="oncommand">
                <xsl:value-of select="concat('navigator.toForum(',@id,',&quot;',@url,'&quot;);')" />
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
    <xsl:template match="forum" mode="expand">
        <xsl:element name="menu">
            <xsl:attribute name="label">
                <xsl:value-of select="@name" />
            </xsl:attribute> 
            <xsl:attribute name="tooltiptext">
                <xsl:value-of select="@name" />
            </xsl:attribute> 
            <menupopup>  
                <xsl:apply-templates select="." mode="single" />
                <menuseparator />
                <xsl:apply-templates select="forum" mode="single" />
            </menupopup>
        </xsl:element>  
    </xsl:template>
</xsl:stylesheet>
